//pinia 仓库写法：组合式 API，选择式 API
import { defineStore } from 'pinia'
//引入医院详情数据请求方法
import { reqHospitalDetail, reqHospitalDeparment } from '@/api/hospital'
//引入医院详情数据的 TS 类型
import type { HosPitalDetailData } from '@/api/hospital/type'
import type { HosPitalDetail, DeparmentResponseData } from '@/api/hospital/type'
import type { DetailState } from './interface/'
const useDetailStore = defineStore('Detail', {
  state: (): DetailState => {
    return {
      //医院详情的数据
      hospitalInfo: {} as HosPitalDetailData,
      //存储医院科室的数据
      deparmentArr: []
    }
  },
  actions: {
    //获取医院详情的方法
    async getHospital(hoscode?: string) {
      if (!hoscode) return
      const result: HosPitalDetail = await reqHospitalDetail(hoscode)
      console.log(result)
      if (result.code == 200) {
        //医院详情的数据
        this.hospitalInfo = result.data
      }
    },
    //获取某一个医院科室的数据
    async getDeparment(hoscode?: string) {
      if (!hoscode) return
      const result: DeparmentResponseData = await reqHospitalDeparment(hoscode)
      if (result.code == 200) {
        this.deparmentArr = result.data
      }
    }
  },
  getters: {}
})

//获取仓库的方法对外暴露
export default useDetailStore
